# src = $(wildcard src/*.cpp) $(wildcard src/*/*/*.cpp) $(wildcard src/config/*.cpp)
src = $(shell find . -name *.cpp)
bin_dir = bin
obj = $(src:cpp=o)
h_path = $(shell find . -name *.h)
# Debug模式
ifeq ($(debug), true)
	CXXFLAGS = -g -std=c++11 -Wall
else
	CXXFLAGS = -std=c++11 -Wall -O3
endif

ifeq ($(target), windows)
	cc = i686-w64-mingw32-g++-posix $(CXXFLAGS)
else
	cc = g++ $(CXXFLAGS)
endif
CXXFLAGS += $(addprefix -I,$(dir $(h_path)))
default:
	@echo compile started
	@make main -j8 debug=$(debug)
	@echo "\033[0;35mExecutable file at $(shell pwd)/$(bin_dir)/main"
	@echo "Configure file at $(shell pwd)/$(bin_dir)/config.conf"
	@echo "\033[0;32mFinish!\033[0;0m"
debug:
	# make clean
	make default debug=true
	@echo "\033[0;31m"
	@echo "	You are using DEBUG MODE"
	@echo "Use this version in production environment is NOT RECOMMANDED"
	@echo "If you want to run in production environment, please use \033[0;32m\"make clean default\"\033[0;0m"
	@echo "\033[0;0m"
run: debug
	./$(bin_dir)/main -c $(bin_dir)/config.conf
main: $(obj)
	@echo Linking target files
	$(cc) $(obj) -o $(bin_dir)/main -lpthread
windows: 
	make build-windows target=windows -j8
build-windows:$(obj)
	$(cc) $(obj) -o $(bin_dir)/main.exe -lpthread -lws2_32 -static

%.o: %.cpp
	$(cc) -c $^ -o $@ $(CXXFLAGS)
clean:
	-@rm $(src:cpp=o)
	-@rm $(bin_dir)/main
